<style>
	input{border: 1px solid #DDDDDD;border-radius: 5px;}
</style>
<div class="row" style="margin-bottom: 20px;border-bottom: 1px solid #EEEEEE;">
<a href="{:U('Sys/index')}"><button type="button" class="btn btn-primary">网站配置</button></a>
<a href="{:U('Sys/seo')}"><button type="button" class="btn btn-primary">SEO优化</button></a>
<a href="{:U('Sys/nav')}"><button type="button" class="btn btn-primary active">导航管理</button></a>
<a href="{:U('Sys/updateCount')}"><button type="button" class="btn btn-primary">更新统计与数据</button></a>
<a href="{:U('Sitemap/index')}"><button type="button" class="btn btn-primary">生成站点地图</button></a>
</div>
<div class="row">
	<div class="panel panel-primary">
	   <div class="panel-body">
	   	<form action="" class="subnav" method="post">
	      <table class="table table-hover">
			   <thead>
			      <tr>
			         <th>排序</th>
			         <th>名称</th>
			         <th>网址</th>
			         <th>状态</th>
			         <th>操作</th>
			      </tr>
			   </thead>
			   <tbody>
			   	<volist name="data" id="data">
			      <tr>
			         <td><input type="number" name="sort[]" value="{$data['sort']}"/></td>
			         <td><input type="text" name="name[]" value="{$data['name']}"/></td>
			         <td>
			         	<input type="hidden" name="id[]" value="{$data['id']}"/>
			         	<input type="hidden" name="flag[]" value="{$data['flag']}" />
			         		<switch name="data.flag">
			         			<case value="index">
			         				<a href="{:U('Home/Index/index')}" target="_blank">查看</a>
			         			</case>
								<case value="video">
									<a href="{:U('Home/Video/index')}" target="_blank">查看</a>
								</case>
								<case value="music">
									<a href="{:U('Home/Music/index')}" target="_blank">查看</a>
								</case>
								<case value="album">
									<a href="{:U('Home/Album/index')}" target="_blank">查看</a>
								</case>
								<case value="torrent">
									<a href="{:U('Home/Torrent/index')}" target="_blank">查看</a>
								</case>
								<case value="software">
									<a href="{:U('Home/Software/index')}" target="_blank">查看</a>
								</case>
								<case value="tag">
									<a href="{:U('Home/Tag/index')}" target="_blank">查看</a>
								</case>
								<case value="news">
									<a href="{:U('Home/News/index')}" target="_blank">查看</a>
								</case>
								<case value="user">
									<a href="{:U('Home/User/index')}" target="_blank">查看</a>
								</case>
								<case value="book">
									<a href="{:U('Home/Book/index')}" target="_blank">查看</a>
								</case>
								<case value="zip">
									<a href="{:U('Home/Zip/index')}" target="_blank">查看</a>
								</case>
								<default /><a href="{$data['site']}" target="_blank">查看</a>
			         		</switch>
			         	<!--<a href="{:U('Home/Index/index')}" target="_blank">查看</a>-->
			         </td>
			         <td>
			         	<if condition="$data.isopen eq 1">
			         		<span style="color: green;">开启</span>
			         	<else/>
			         		<span style="color: red;">关闭</span> 
			         	</if>
			         </td>
			         <td>
			         	<if condition="$data.isopen eq 1">
			         		<a href="javascript:void(0);" class="closeBtn" data-id="{$data['id']}">关闭</a> 
			         	<else/>
			         		<a href="javascript:void(0);" class="open" data-id="{$data['id']}">开启</a>
			         	</if>
			         	<if condition="$data.flag eq 'diy'">
			         		<a href="javascript:void(0);" class="delete" data-id="{$data['id']}">删除</a> 
			         	</if>
			         </td>
			      </tr>
			     </volist>
			   </tbody>
			</table>
	   	</form>
	   	<div class="col-xs-12 text-right">
	   		<button class="btn btn-default" id="add">新增导航</button> 
			<button class="btn btn-default" id="submitBtn">提交修改</button>
	   	</div>
	   </div>
	</div>
</div>
<!--模态框-->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-body">
         	<form method="post" class="addnav" role="form" action="{:U('Sys/addNav')}">
			   <div class="form-group">
			      <label for="addname">名称</label>
			      <input type="text" class="form-control" name="name" id="addname" placeholder="请输入导航名称">
			   </div>
			   <div class="form-group">
			      <label for="addsort">排序</label>
			      <input type="number" name="sort" class="form-control" id="addsort" value="0">
			   </div>
			   <div class="form-group">
			      <label for="addsite">网址</label>
			      <input type="text" class="form-control" name="site" id="addsite" placeholder="请输入网址">
			   </div>
			   <div class="form-group">
			   	 <label for="addsite">状态</label>
				    <label class="checkbox-inline">
				      <input type="radio" name="isopen" value="1" checked>开启
				   	</label>
				   	<label class="checkbox-inline">
				      <input type="radio" name="isopen" value="0">关闭
				   	</label>
			   </div>
         	</form>
         </div>
         <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            <button type="button" class="btn btn-default addnavbtn">确定添加</button>
         </div>
      </div><!-- /.modal-content -->
</div><!-- /.modal -->
<script>
	$(function(){
		$('#submitBtn').click(function(){
			$('form.subnav').submit();
		});
		$('.closeBtn').click(function(){
			$.get("{:U('Sys/nav_isopen')}",{id:$(this).attr('data-id'),isopen:0},function(ret){
				if(ret==1){
					location.reload();
				}else{
					alert('关闭失败。如果当前页面为首页，则不能对当前页面进行关闭。');
				}
			});
		});
		$('.open').click(function(){
			$.get("{:U('Sys/nav_isopen')}",{id:$(this).attr('data-id'),isopen:1},function(ret){
				if(ret==1){
					location.reload();
				}else{
					alert('开启失败。。请刷新页面后重试');
				}
			});
		});
		
		$("#add").click(function(){
			$('#myModal').modal('show');
		});
		$('.addnavbtn').click(function(){
			$('form.addnav').submit();
		});
		
		$('.delete').click(function(){
			if(confirm('您确定要删除当前导航吗？')){
				$.get("{:U('Sys/deleteNav')}",{id:$(this).attr('data-id')},function(){
					location.reload();
				});
			}
		});
	});
</script>






